<template>
	<div>
		<div class="commonWidth">
			<el-row style="margin-bottom: 10px">
				<el-col :span="24" align="right">
					<el-input v-model="entName" size="small" class="element-width" placeholder="请输入企业名称"
						@keyup.enter.native="search"></el-input>
					<el-date-picker size="small" v-model="startTime" class="element-width" type="date"
						value-format="yyyy-MM-dd" placeholder="选择开始日期" @change="search">
					</el-date-picker>
					<el-date-picker size="small" v-model="endTime" class="element-width" type="date"
						value-format="yyyy-MM-dd" placeholder="选择结束日期" @change="search">
					</el-date-picker>
					<el-select v-model="isView" placeholder="请选择状态" class="element-width" clearable @change="search"
						size="small">
						<el-option v-for="item in statusList" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
					<el-select v-model="rectificationStatus" class="element-width" placeholder="请选择追踪情况" clearable
						@change="search" size="small">
						<el-option v-for="item in rectificationStatusList" :label="item.label" :value="item.value">
						</el-option>
					</el-select>

				</el-col>
			</el-row>
			<el-table :data="list" border style="width:100%" @selection-change="handleSelectionChange">

				<el-table-column prop="userName" label="提交人">
				</el-table-column>
				<el-table-column prop="createTime" label="创建时间">
					<template scope="scope">
						{{scope.row.createTime.substring(0, 16)}}
					</template>
				</el-table-column>
				<el-table-column prop="createTime" label="整改项">
					<template scope="scope">
						<span v-if="scope.row.isView == 0">未点评</span>
						<span v-else-if="scope.row.errorNo == 0">无需整改</span>
						<span v-else style="color: #22bd33;cursor: pointer"
							@click="getErrorEntSelfExamineItemList(scope.row)">{{scope.row.rectifyNo}}/{{scope.row.errorNo}}</span>
					</template>
				</el-table-column>
				<el-table-column label="整改前得分">
					<template scope="scope">
						<span v-if="scope.row.isView == 0">未点评</span>
						<span v-else>{{scope.row.beforeRectifyScore || 0}}</span>
					</template>
				</el-table-column>
				<el-table-column label="整改后得分">
					<template scope="scope">
						<span v-if="scope.row.isView == 0">未点评</span>
						<span v-else-if="scope.row.errorNo == 0">无需整改</span>
						<span v-else-if="scope.row.rectifyNo == 0">未追踪</span>
						<span v-else>{{scope.row.afterRectifyScore}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="createTime" width="220" label="操作">
					<template scope="scope">
						<el-button type="text" size="small" @click="checkEntSelfExamineItemList(scope.row)">查看
						</el-button>
						<el-button type="text" size="small" @click="getEntSelfExamineItemList(scope.row)">评价</el-button>
						<el-button type="text" size="small" @click="createFile(scope.row)">导出</el-button>
						<!-- <el-button type="text" size="small" @click="getUrl(scope.row)">分享</el-button>
						<el-button type="text" size="small" @click="getPlanByEntId(scope.row)">应用</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<div v-show="list&&list.length>0" align="right">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page.sync="pageIndex" :page-sizes="[10,20,30,50]" :page-size="pageSize"
					layout="total, sizes, prev, pager, next, jumper" :total="total">
				</el-pagination>
			</div>
		</div>
		<el-dialog :visible.sync="showCheckVisible" width="800px" :title="info.entName + '--规范化检测查看'">
			<div class="">
				<div class="examine-title">{{currentIndex + 1}}、{{currentItem.title}}</div>
				<div class="question-title" v-for="(obj, objIndex) in currentItem.questions">
					<div>（{{objIndex + 1}}）{{obj.title}}</div>
					<div style="display: inline-block;margin-left: 35px;">检查结果：</div>
					<div v-for="(option, optionIndex) in obj.options" style="display: inline-block;margin-right: 30px;">
						<div class="select-img" :class="option.isSelect == 1 ? 'select' : ''"></div>
						<div style="display: inline-block">{{option.name}}</div>
					</div>
					<div class="option-container">
						<div>检查详情：{{obj.remark || '--'}}</div>
						<div class="img-list">
							<div class="img-item" v-for="img in obj.imgList" @click="viewImg(img)">
								<img :src="img">
							</div>
						</div>
						<div v-if="obj.standardsList.length > 0">评分：</div>
						<div v-for="(standards, standardsIndex) in obj.standardsList" class="standards-option">
							<div style="margin-bottom: 5px">{{standardsIndex + 1}}. {{standards.title}}</div>
							<el-checkbox-group v-model="standards.selectList" style="margin-bottom: 20px;"
								v-if="standards.type == 'CHECKBOX'" disabled>
								<el-checkbox style="display: flex" :label="standardsItem.id"
									v-for="standardsItem in standards.standardItemList">
									{{standardsItem.title}}（{{standardsItem.score}}分）
								</el-checkbox>
							</el-checkbox-group>
							<el-radio-group v-model="standards.result" v-else disabled>
								<el-radio :label="standardsItem.id" v-for="standardsItem in standards.standardItemList">
									{{standardsItem.title}}（{{standardsItem.score}}分）
								</el-radio>
							</el-radio-group>
						</div>
						<div>需要整改：
							<el-select v-model="obj.rectifyStatus" disabled style="margin-bottom: 10px">
								<el-option v-for="item in rectifyStatusErrorList" :label="item.name" :value="item.code">
								</el-option>
							</el-select>
						</div>
						<div v-if="obj.rectifyStatus != 'NOT_NEED_RECTIFY'">整改意见：{{obj.rectifyAdvice}}</div>
						<div style="display: flex;line-height: 40px;" v-if="obj.rectifyStatus != 'NOT_NEED_RECTIFY'">
							<div>整改完成时间：{{getDateStr(obj.rectifyTime) || '--'}}</div>
						</div>
						<div v-if="obj.rectifyStatus != 'NOT_NEED_RECTIFY' && obj.rectification"
							style="margin-top: 20px;">
							<div style="margin-bottom: 5px;">整改结果：{{obj.rectification.statusStr}}</div>
							<div style="margin-bottom: 5px;">整改说明：{{obj.rectification.remark || '--'}}</div>
							<div style="margin-bottom: 5px;">完成时间：{{getDateStr(obj.rectification.completeTime) || '--'}}
							</div>
							<div v-for="(img, idx) in obj.rectification.fileList" class="img-item">
								<img :src="img.url" @click="viewImg(img.url)">
							</div>
							<div v-for="(standards, standardsIndex) in obj.rectification.standardsList"
								class="standards-option">
								<div style="margin-bottom: 5px">{{standardsIndex + 1}}. {{standards.title}}</div>
								<el-checkbox-group v-model="standards.selectList" style="margin-bottom: 20px;"
									v-if="standards.type == 'CHECKBOX'" disabled>
									<el-checkbox style="display: flex" :label="standardsItem.id"
										v-for="standardsItem in standards.standardItemList">
										{{standardsItem.title}}（{{standardsItem.score}}分）
									</el-checkbox>
								</el-checkbox-group>
								<el-radio-group v-model="standards.result" v-else disabled>
									<el-radio :label="standardsItem.id"
										v-for="standardsItem in standards.standardItemList">
										{{standardsItem.title}}（{{standardsItem.score}}分）
									</el-radio>
								</el-radio-group>
							</div>
						</div>
					</div>
				</div>
			</div>
			<span slot="footer" class="dialog-footer" style="text-align: center!important;">
				<el-button @click="preItem" v-if="currentIndex > 0">上一项</el-button>
				<el-button type="primary" @click="nextAction" v-if="info.list && currentIndex < info.list.length - 1">
					下一项
				</el-button>
			</span>
		</el-dialog>
		<el-dialog :visible.sync="visible" width="800px" :title="info.entName + '--规范化检测'">
			<div class="">
				<div class="examine-title">{{currentIndex + 1}}、{{currentItem.title}}</div>
				<div class="question-title" v-for="(obj, objIndex) in currentItem.questions">
					<div>（{{objIndex + 1}}）{{obj.title}}</div>
					<div style="display: inline-block;margin-left: 35px;">检查结果：</div>
					<div v-for="(option, optionIndex) in obj.options" style="display: inline-block;margin-right: 30px;">
						<div @click="selectOption(objIndex, optionIndex)" class="select-img"
							:class="option.isSelect == 1 ? 'select' : ''"></div>
						<div style="display: inline-block">{{option.name}}</div>
					</div>
					<div class="option-container">
						<el-input style="margin-top: 5px" class="option-text" type="textarea" :autosize="{ minRows: 3}"
							placeholder="请填写详细情况" v-model="obj.remark"></el-input>
						<div class="img-list">
							<div class="img-item" v-for="img in obj.imgList" @click="viewImg(img)">
								<img :src="img">
							</div>
						</div>
						<div v-if="obj.standardsList.length > 0">评分：</div>
						<div v-for="(standards, standardsIndex) in obj.standardsList" class="standards-option">
							<div style="margin-bottom: 5px">{{standardsIndex + 1}}. {{standards.title}}</div>
							<el-checkbox-group v-model="standards.selectList" style="margin-bottom: 20px;"
								v-if="standards.type == 'CHECKBOX'">
								<el-checkbox style="display: flex" :label="standardsItem.id"
									v-for="standardsItem in standards.standardItemList">
									{{standardsItem.title}}（{{standardsItem.score}}分）
								</el-checkbox>
							</el-checkbox-group>
							<el-radio-group v-model="standards.result" v-else>
								<el-radio :label="standardsItem.id" v-for="standardsItem in standards.standardItemList">
									{{standardsItem.title}}（{{standardsItem.score}}分）
								</el-radio>
							</el-radio-group>
						</div>
						<div style="margin-bottom: 10px">
							需要整改：
							<el-select v-model="obj.rectifyStatus">
								<el-option v-for="item in rectifyStatusErrorList" :label="item.name" :value="item.code">
								</el-option>
							</el-select>
						</div>
						<el-input class="option-text" type="textarea" :autosize="{ minRows: 3}" placeholder="请填写整改意见"
							v-model="obj.rectifyAdvice" v-if="obj.rectifyStatus != 'NOT_NEED_RECTIFY'"></el-input>
						<div style="display: flex;margin-top: 10px;line-height: 40px;"
							v-if="obj.rectifyStatus != 'NOT_NEED_RECTIFY'">
							<div>整改完成时间：</div>
							<el-date-picker v-model="obj.rectifyTime" type="date" placeholder="整改完成时间">
							</el-date-picker>
						</div>
					</div>
				</div>
			</div>
			<span slot="footer" class="dialog-footer" style="text-align: center!important;">
				<el-button @click="preItem" v-if="currentIndex > 0">上一项</el-button>
				<el-button type="primary" @click="nextItem" v-if="currentIndex < info.list.length - 1">下一项</el-button>
				<el-button type="primary" v-else :loading="loading" @click="saveOrUpdate">完成</el-button>
			</span>
		</el-dialog>
		<el-dialog :visible.sync="showError" width="800px" :title="errorEntName + '--整改项'">
			<div>
				<div class="examine-title">{{errorIndex + 1}}、{{errorItem.title}}</div>
				<div style="display: inline-block;margin: 5px 0 5px 27px;">检查结果：</div>
				<div v-for="(option, optionIndex) in errorItem.options" style="display: inline-block;"
					v-if="option.isSelect == 1">
					<div style="display: inline-block">{{option.name}}</div>
				</div>
			</div>
			<div class="option-container" style="margin: 0 0 10px 27px;">
				<div>详细情况：{{errorItem.remark}}</div>
				<div class="img-list">
					<div class="img-item" v-for="img in errorItem.imgList" @click="viewImg(img)">
						<img :src="img">
					</div>
				</div>
				<div class="examine-title" style="margin: 40px 0px 5px 0;">整改意见<span class="edit-btn" v-if="!isEdit"
						@click="isEdit = true">修改</span></div>
				<div v-if="!isEdit">
					<div>整改方式：{{errorItem.rectifyStatusStr || '--'}}</div>
					<div>{{errorItem.rectifyAdvice}}</div>
					<div style="margin-top: 5px;">
						整改截止时间：{{errorItem.rectifyTime ? errorItem.rectifyTime.substring(0, 10) : '--'}}</div>
				</div>
				<div v-else>
					<el-input class="option-text" type="textarea" :autosize="{ minRows: 3}" placeholder="请填写整改意见"
						v-model="errorItem.rectifyAdvice"></el-input>
					<div style="display: flex;margin-top: 10px;line-height: 40px;">
						<div>整改完成时间：</div>
						<el-date-picker v-model="errorItem.rectifyTime" type="date" placeholder="整改完成时间">
						</el-date-picker>
						<el-button type="primary" @click="updateRectifyAdvice" style="margin-left: 10px;"
							:loading="adviceLoading">提交</el-button>
					</div>
				</div>
				<div v-if="errorItem.rectification">
					<div class="examine-title" style="margin: 40px 0px 5px 0;">整改后材料</div>
					<el-select v-model="errorItem.rectification.status" placeholder="类型">
						<el-option v-for="item in rectifyStatusList" :label="item.name" :value="item.code">
						</el-option>
					</el-select>
					<div class="img-list">
						<el-upload style="display: inline-block" action="#" :auto-upload="false" :show-file-list="false"
							:on-change="changeFileList">
							<div class="upload-btn">上传图片</div>
						</el-upload>
						<div v-for="(obj, idx) in fileList" class="img-item">
							<img :src="obj.url" @click="viewImg(obj.url)">
						</div>
					</div>
					<el-input class="option-text" type="textarea" :autosize="{ minRows: 3}" placeholder="请填写整改说明"
						v-model="errorItem.rectification.remark"></el-input>
					<div v-if="errorItem.standardsList.length > 0" style="margin-top: 10px;">评分：</div>
					<div v-for="(standards, standardsIndex) in errorItem.standardsList" class="standards-option">
						<div style="margin-bottom: 5px">{{standardsIndex + 1}}. {{standards.title}}</div>
						<el-checkbox-group v-model="standards.selectList" style="margin-bottom: 20px;"
							v-if="standards.type == 'CHECKBOX'">
							<el-checkbox style="display: flex" :label="standardsItem.id"
								v-for="standardsItem in standards.standardItemList">
								{{standardsItem.title}}（{{standardsItem.score}}分）
							</el-checkbox>
						</el-checkbox-group>
						<el-radio-group v-model="standards.result" v-else>
							<el-radio :label="standardsItem.id" v-for="standardsItem in standards.standardItemList">
								{{standardsItem.title}}（{{standardsItem.score}}分）
							</el-radio>
						</el-radio-group>
					</div>
					<div style="display: flex;margin-top: 10px;line-height: 40px;">
						<div>整改完成时间：</div>
						<el-date-picker v-model="errorItem.rectification.completeTime" type="date" placeholder="整改完成时间">
						</el-date-picker>
						<el-button type="primary" @click="submitRectifyEntQuestionModel" style="margin-left: 10px;"
							:loading="errorLoading">提交</el-button>
					</div>
				</div>
			</div>
			<span slot="footer" class="dialog-footer" style="text-align: center!important;">
				<el-button @click="preErrorItem" v-if="errorIndex > 0">上一项</el-button>
				<el-button type="primary" @click="nextErrorItem" v-if="errorIndex < errorList.length - 1">下一项
				</el-button>
			</span>
		</el-dialog>
		<el-dialog :visible.sync="imgDialogVisible" width="90%" :modal-append-to-body="false" title="查看图片">
			<img :src="dialogImageUrl" alt="" style="width: 100%;height: 100%">
		</el-dialog>
		<el-dialog :visible.sync="linkShow" :modal-append-to-body="false" width="600px">
			<div style="margin: 0 auto;">
				<el-input v-model="link" style="width: 340px;" id="linkInput"></el-input>
				<el-button type="primary" @click="copyUrl" style="margin-left: 5px;">复制链接</el-button>
			</div>
		</el-dialog>
		<el-dialog :visible.sync="showPlan" :title="'应用--' + currentExamine.entName" width="800px">
			<el-table ref="planTable" :data="planList" border style="width: 100%">
				<el-table-column prop="planName" label="计划名称">
				</el-table-column>
				<el-table-column prop="planSource" label="计划来源">
				</el-table-column>
				<el-table-column label="开始结束时间">
					<template scope="scope">
						<span>{{scope.row.startTime.substring(0, 10)}}~{{scope.row.endTime.substring(0, 10)}}</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="120">
					<template scope="scope">
						<el-button type="text" size="small" @click="applyEntSelfExaminePlanRelation(scope.row)">应用
						</el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-dialog>
	</div>
</template>

<script>
	let that
	let APPKEY = '5da5441f62e48aedc7a3853ffc75c2db'
	let PRODID = 'gf'
	let UPLOAD_ACTION = '/upload'
	let VIEW_ACTION = '/view'
	let REMOVE_ACTION = '/remove'
	let IMGURL = 'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload'
	let fileViewUrl =
		'https://www.weifeibangbang.com/wfbb-webupload/service/sys/file/upload/view?appKey=5da5441f62e48aedc7a3853ffc75c2db&prodID=gf&fileID='
	import $ from 'jquery'

	export default {
		data() {
			return {


				params: {},
				list: [],
				pageIndex: 1,
				pageSize: 10,
				total: 0,
				param: {},
				loading: false,
				visible: false,
				info: {
					list: [{
						title: '',
						questions: [{
							title: '',
							options: [{}],
							examples: [],
							imgList: []
						}]
					}]
				},
				outLoading: false,
				subjectId: '',
				//uploadAction: upload.IMGURL + '/upload',
				contractParam: {
					'appKey': APPKEY,
					'prodID': PRODID,
					businessCode: ''
				},
				multipleSelection: [],
				fileList: [],
				isUpload: false,
				index: 0,
				objIndex: 0,
				imgIndex: 0,
				imgDialogVisible: false,
				dialogImageUrl: '',
				statusList: [{
						label: '已点评',
						value: 1
					},
					{
						label: '未点评',
						value: 0
					},
				],
				isView: '',
				currentIndex: 0,
				currentItem: {},
				entName: '',
				errorList: [],
				errorIndex: 0,
				errorItem: {},
				showError: false,
				errorEntName: '',
				fileList: [],
				fileIdList: [],
				errorLoading: false,
				isEdit: false,
				adviceLoading: false,
				rectifyStatusList: [{
						code: 'NOT_RECTIFY',
						name: '未整改'
					},
					{
						code: 'ONGOING_RECTIFY',
						name: '整改中'
					},
					{
						code: 'HAVE_RECTIFY',
						name: '已整改'
					}
				],
				linkShow: false,
				link: '',
				showCheckVisible: false,
				startTime: '',
				endTime: '',
				tagList: [],
				allTagList: [],
				rectificationStatusList: [{
						label: '需整改，未追踪',
						value: 'NOT_RECTIFICATION'
					},
					{
						label: '需整改，已追踪',
						value: 'HAVE_RECTIFICATION'
					},
					{
						label: '无需整改',
						value: 'NOT_NEED_RECTIFICATION'
					},
				],
				rectificationStatus: '',
				planList: [],
				currentExamine: {},
				showPlan: false,
				rectifyStatusErrorList: [{
						code: 'NOT_NEED_RECTIFY',
						name: '无需整改'
					},
					{
						code: 'ADVICE_RECTIFY',
						name: '建议整改'
					},
					{
						code: 'COMPEL_RECTIFY',
						name: '强制整改'
					}
				],
			}
		},
		created: function() {},
		mounted: function() {
			that = this
			that.params.facilitatorId = that.getQueryString("facilitatorId")
			that.params.ticketId = that.$store.state.token
			that.params.subjectId = that.getQueryString("subjectId")
			that.subjectId = that.getQueryString("subjectId")

			this.pageSubmitEntSelfExamine();
		},

		methods: {
			applyEntSelfExaminePlanRelation(item) {
				const _this = this;
				that.ajax({
					url: '/entSelfExamine/applyEntSelfExaminePlanRelation?ticketId=' + that.params.ticketId,
					data: {
						subjectId: _this.subjectId,
						planId: item.planId,
						planEntId: item.planEntId,
						examineMainId: _this.currentExamine.id
					},
					dataType: 'json',
					success: function(result) {
						if (result.status == 1 && result.data) {
							that.$message.success('应用成功');
							_this.showPlan = false;
						}
					}
				})
			},
			getPlanByEntId(item) {
				const _this = this;
				_this.currentExamine = item;
				_this.showPlan = true;
				_this.getEntSelfExaminePlanByEntId();
			},
			getEntSelfExaminePlanByEntId() {
				const _this = this;
				that.ajax({
					url: '/entSelfExamine/getEntSelfExaminePlanByEntId?ticketId=' + that.params.ticketId,
					data: {
						subjectId: _this.subjectId,
						entId: _this.currentExamine.entId
					},
					dataType: 'json',
					success: function(result) {
						if (result.status == 1 && result.data) {
							_this.planList = result.data;
						}
					}
				})
			},

			getDateStr: function(dateStr) {
				if (!dateStr) {
					return null;
				}
				var date = new Date(dateStr);
				return dateFormat(date, 'yyyy-MM-dd')
			},
			getUrl: function(item) {
				var _this = this;
				_this.link = 'https://www.weifeibangbang.com/view/questionnaire?id=' + item.id;
				_this.linkShow = true;
			},
			copyUrl: function() {
				var Url2 = document.getElementById("linkInput");
				Url2.select(); // 选择对象
				document.execCommand("Copy");
				this.$message({
					message: '复制链接成功',
					type: 'success'
				});
			},
			changeFileList: function(file, fileList) {
				var _this = this;
				file.raw.url = URL.createObjectURL(file.raw);
				_this.fileList.push(file.raw);
			},
			deleteFile: function(index, idx) {
				var _this = this;
				_this.fileList.splice(idx, 1);
			},
			selectOption: function(objIndex, optionIndex) {
				var _this = this;
				var remark = '';
				_this.currentItem.questions[objIndex].options.forEach(function(t) {
					if (t.isSelect == 1) {
						remark = t.remark;
					}
					t.isSelect = 0;
				})
				_this.currentItem.questions[objIndex].options[optionIndex].isSelect = 1;
				_this.currentItem.questions[objIndex].options[optionIndex].remark = remark;
			},
			viewImg: function(val) {
				var vm = this;
				vm.dialogImageUrl = val;
				vm.imgDialogVisible = true;
			},
			chooseUpload: function(index, objIndex, imgIndex) {
				this.index = index;
				this.objIndex = objIndex;
				this.imgIndex = imgIndex;
			},
			delExample: function(index, objIndex, imgIndex) {
				this.info.list[index].questions[objIndex].examples.splice(imgIndex, 1);
			},
			addExample: function(index, objIndex) {
				this.info.list[index].questions[objIndex].examples.push({})

			},
			delOption: function(index, objIndex, optionIndex) {
				this.info.list[index].questions[objIndex].options.splice(optionIndex, 1);

			},
			addOption: function(index, objIndex) {
				this.info.list[index].questions[objIndex].options.push({})
			},
			delObj: function(index, objIndex) {
				this.info.list[index].questions.splice(objIndex, 1);
			},
			addObj: function(index) {
				var item = {
					title: '',
					options: [{}],
					examples: [{}],
					imgList: []
				}
				this.info.list[index].questions.push(item)
			},
			delItem: function(index) {
				this.info.list.splice(index, 1);
			},
			addItem: function() {
				var item = {
					title: '',
					questions: [{
						title: '',
						options: [{}],
						examples: [{}],
						imgList: []
					}]
				}
				this.info.list.push(item);
			},
			handleRemove: function(file) {
				if (file.response) {
					upload.delete(file.response.message.fileID);
				}
			},
			saveOrUpdate: function() {
				vue.deposit();
			},
			contractUploadSuccess: function(response, file, fileList) {
				var _this = this;
				if (!file.response.success) {
					that.$message.error('文件上传失败');
					return;
				}
				var obj = file.response.message;
				_this.info.list[_this.index].questions[_this.objIndex].examples[_this.imgIndex].fileId = obj.fileID;
				console.log(_this.info);
			},
			handleContractSuccess: function(file, fileList) {
				var fileExtension = file.name.split('.')[1];
				if (fileExtension != 'jpg' && fileExtension != 'png' && fileExtension != 'jpeg') {
					this.$message.error('文件只能是图片格式!');
					this.$refs.contractUpload.clearFiles();
					return;
				}
			},
			search: function() {
				this.pageIndex = 1;
				this.list = [];
				this.pageSubmitEntSelfExamine();
			},
			pageSubmitEntSelfExamine: function() {
				var vm = this;
				that.ajax({
					url: '/selfExamine/pageBbepSubmitEntSelfExamine?ticketId=' + that.params.ticketId +
						'&pageIndex=' + this.pageIndex + '&pageSize=' + this.pageSize,
					data: JSON.stringify({
						isView: vm.isView,
						entName: vm.entName,
						subjectId: vm.subjectId,
						startTime: vm.startTime,
						endTime: vm.endTime,
						tagList: vm.tagList,
						rectificationStatus: vm.rectificationStatus,
						examineType: "WASTE_GAS"
					}),
					contentType: 'application/json',
					dataType: 'json',
					success: function(result) {
						if (result.status == 1) {
							vm.list = result.data.records;
							vm.total = result.data.total;
						}
					}
				})
			},
			createFile: function(item) {
				window.location.href = '/selfExamine/createFile?ticketId= ' + that.params.ticketId + '&id=' + item
					.id + '&entName=' + item.entName;
			},
			getErrorEntSelfExamineItemList: function(item) {
				var vm = this;
				that.ajax({
					url: ' /selfExamine/getErrorEntSelfExamineItemList?ticketId=' + that.params.ticketId,
					data: {
						id: item.id
					},
					dataType: 'json',
					success: function(result) {
						if (result.status == 1) {
							var list = result.data;
							list.forEach(function(obj) {
								for (var i in obj.imgList) {
									obj.imgList[i] = IMG_VIEW_URL + '&fileID=' + obj.imgList[i]
								}
							})
							vm.errorEntName = item.entName;
							vm.errorIndex = 0
							vm.errorList = list;
							vm.formatErrorItem();
							vm.showError = true;
						}
					}
				})
			},
			checkEntSelfExamineItemList: function(val) {
				var vm = this;
				vm.info = {};
				vm.currentIndex = 0;
				vm.currentItem = {};
				var item = JSON.parse(JSON.stringify(val));
				that.ajax({
					url: ' /selfExamine/getEntSelfExamineItemList?ticketId= ' + that.params.ticketId,
					data: {
						id: item.id,
						rectificationFlag: true
					},
					dataType: 'json',
					success: function(result) {
						if (result.status == 1) {
							var list = result.data;
							list.forEach(function(t) {
								t.questions.forEach(function(obj) {
									for (var i in obj.imgList) {
										obj.imgList[i] = IMG_VIEW_URL + '&fileID=' + obj
											.imgList[i]
									}
									var rectification = obj.rectification;
									if (rectification) {
										var fileList = [];
										if (rectification.fileId) {
											var fileIdList = rectification.fileId.split(
												",");
											fileIdList.forEach(function(t) {
												fileList.push({
													url: IMG_VIEW_URL +
														'&fileID=' + t,
													fileId: t
												})
											})
										}
										rectification.fileList = fileList;
									}
									obj.rectification = rectification;
								})
							});
							item.list = list;
							vm.info = item;
							vm.currentItem = item.list[0];
							vm.showCheckVisible = true;
						}
					}
				})
			},
			getEntSelfExamineItemList: function(val) {
				var vm = this;
				vm.info = {};
				vm.currentIndex = 0;
				vm.currentItem = {};
				var item = JSON.parse(JSON.stringify(val));
				that.ajax({
					url: '/selfExamine/getEntSelfExamineItemList?ticketId=' + that.params.ticketId,
					data: {
						id: item.id,
						examineType: "WASTE_GAS"
					},
					dataType: 'json',
					success: function(result) {
						if (result.status == 1) {
							var list = result.data;
							list.forEach(function(t) {
								t.questions.forEach(function(obj) {
									for (var i in obj.imgList) {
										obj.imgList[i] = IMG_VIEW_URL + '&fileID=' + obj
											.imgList[i]
									}
								})
							});
							item.list = list;
							vm.info = item;
							vm.currentItem = item.list[0];
							vm.visible = true;
						}
					}
				})
			},
			handleSizeChange: function(val) {
				this.pageIndex = 1;
				this.pageSize = val;
				this.pageSubmitEntSelfExamine();
			},
			handleCurrentChange: function(val) {
				this.pageIndex = val;
				this.pageSubmitEntSelfExamine();
			},
			handleSelectionChange: function(val) {
				this.multipleSelection = val;
			},
			deposit: function() {
				var vm = this;
				vm.loading = true;
				vm.formatSubmitItem(vm.currentItem);
				that.ajax({
					url: ' /selfExamine/completeEntSelfExamine?ticketId=' + that.params.ticketId,
					data: JSON.stringify(vm.currentItem),
					contentType: 'application/json',
					dataType: 'json',
					type: 'POST',
					success: function(result) {
						if (result.status == 1) {
							vm.visible = false;
							vm.loading = false;
							vm.pageSubmitEntSelfExamine();
							that.$message.success('评价成功');
						}
					}
				})
			},
			preItem: function() {
				var vm = this;
				vm.currentIndex--;
				vm.currentItem = vm.info.list[vm.currentIndex];
			},
			// 格式化检查项
			formatSubmitItem: function(item) {
				var vm = this;
				item.questions.forEach(function(obj) {
					vm.formatQuestion(obj);
				})
			},
			// 格式化检查项问题
			formatQuestion: function(obj) {
				var standardsList = obj.standardsList;
				var score = 0;
				standardsList.forEach(function(t) {
					var selectList = t.selectList;
					var result = t.result;
					var tempScore = 0;
					if (t.type == 'RADIO') {
						t.standardItemList.forEach(function(e) {
							if (result == e.id) {
								tempScore = e.score;
								return;
							}
						})
					} else {
						t.standardItemList.forEach(function(e) {
							for (var i in selectList) {
								if (e.id == selectList[i]) {
									tempScore += e.score;
									return;
								}
							}
						})
						t.result = selectList.join(",");
					}
					score += tempScore;
					t.score = tempScore;
				})
				obj.score = score;
			},
			nextAction: function() {
				var vm = this;
				vm.currentIndex++;
				vm.currentItem = vm.info.list[vm.currentIndex];
			},
			nextItem: function() {
				var vm = this;
				vm.formatSubmitItem(vm.currentItem);
				that.ajax({
					url: '/selfExamine/updateSubmitEntSelfExamineItem?ticketId=' + that.params.ticketId,
					data: JSON.stringify(vm.currentItem),
					contentType: 'application/json',
					dataType: 'json',
					type: 'POST',
					success: function(result) {
						if (result.status == 1) {
							vm.pageSubmitEntSelfExamine();
							vm.nextAction();
						}
					}
				})
			},
			uploadFile: function(idx) {
				var _this = this;
				var fileList = _this.fileList;
				if (idx >= fileList.length) {
					_this.updateExamineRectification();
					return;
				}
				var file = fileList[idx];
				if (file.fileId) {
					_this.fileIdList.push(file.fileId);
					_this.uploadFile(++idx);
					return;
				}
				var formdata = new FormData()
				formdata.append("file", file);
				formdata.append("appKey", _this.contractParam.appKey);
				formdata.append("businessCode", _this.contractParam.businessCode);
				formdata.append("prodID", _this.contractParam.prodID);
				$.ajax({
					url: IMGURL + '/upload',
					data: formdata,
					dataType: 'json',
					type: 'POST',
					contentType: false,
					processData: false,
					success: function(result) {
						_this.fileIdList.push(result.message.fileID);
						_this.uploadFile(++idx);
					},
					error: function() {
						_this.uploadFile(++idx);
					}
				})
			},
			submitRectifyEntQuestionModel: function() {
				var vm = this;
				if (!vm.errorItem.rectification.remark) {
					return that.$message.error('请填写整改说明');
				}
				if (!vm.errorItem.rectification.completeTime) {
					return that.$message.error('请听写整改日期');
				}
				vm.errorLoading = true;
				vm.uploadFile(0);
			},
			formatErrorItem: function() {
				var vm = this;
				var item = vm.errorList[vm.errorIndex];
				vm.isEdit = false;
				vm.errorItem = item;
				vm.fileList = [];
				vm.fileIdList = [];
				if (vm.errorItem.rectification.fileId) {
					var fileList = [];
					var fileIdList = vm.errorItem.rectification.fileId.split(",");
					fileIdList.forEach(function(t) {
						fileList.push({
							url: IMG_VIEW_URL + '&fileID=' + t,
							fileId: t
						})
					})
					vm.fileList = fileList;
				}
			},
			preErrorItem: function() {
				var vm = this;
				vm.errorIndex--;
				vm.formatErrorItem();
			},
			nextErrorItem: function() {
				var vm = this;
				vm.errorIndex++;
				vm.formatErrorItem();
			},
			updateExamineRectification: function() {
				var vm = this;
				vm.formatQuestion(vm.errorItem);
				var errorItem = JSON.parse(JSON.stringify(vm.errorItem));
				errorItem.rectification.fileId = vm.fileIdList.join(",");
				errorItem.rectification.itemId = errorItem.id;
				errorItem.examineType = "WASTE_GAS"
				that.ajax({
					url: '/selfExamine/updateExamineRectification?ticketId=' + that.params.ticketId,
					data: JSON.stringify(errorItem),
					contentType: 'application/json',
					dataType: 'json',
					type: 'POST',
					success: function(result) {
						if (result.status == 1) {
							vm.errorLoading = false;
							vm.pageSubmitEntSelfExamine();
							return that.$message.success('提交成功');
						}
					}
				})
			},
			updateRectifyAdvice: function() {
				var vm = this;
				var errorItem = JSON.parse(JSON.stringify(vm.errorItem));
				vm.adviceLoading = true;
				that.ajax({
					url: '/selfExamine/updateRectifyAdvice?ticketId=' + that.params.ticketId + '',
					data: JSON.stringify(errorItem),
					contentType: 'application/json',
					dataType: 'json',
					type: 'POST',
					success: function(result) {
						if (result.status == 1) {
							vm.adviceLoading = false;
							vm.isEdit = false;
							return that.$message.success('提交成功');
						}
					}
				})
			}
		}
	}
</script>

<style>
	.el-dialog__footer {
		padding: 10px 20px 20px;
		text-align: center;
		box-sizing: border-box;
	}

	.customer-upload {
		width: 100px;
		height: 100px;
		line-height: 100px;
		background: url(http://www.weifeibangbang.com/main/pc/img/upload.png) center center no-repeat;
		margin-top: 10px;
		position: relative;
		display: inline-block;
		border: 1px dashed #c0ccda
	}

	.el-upload__input {
		display: none !important;
	}

	.el-upload_tip {
		margin-bottom: -15px;
	}

	.el-upload {
		text-align: left;
	}

	.el-upload--picture-card {
		border: 0;
	}

	.el-upload-list--picture-card .el-upload-list__item {
		width: 100px;
		height: 100px;
		margin: 10px 8px 8px 0;
	}

	.examine-title {
		font-size: 16px;
		font-weight: bold;
	}

	.question-title {
		font-size: 14px;
		margin-left: 25px;
	}

	.option-container {
		margin: 0 0 10px 35px;
	}

	.option-text {
		width: 500px;
	}

	.img-list {
		margin-bottom: 10px;
	}

	.img-item {
		display: inline-block;
		width: 100px;
		height: 100px;
		margin: 10px 10px 0 0;
		cursor: pointer;
	}

	.img-item img {
		width: 100%;
		height: 100%;
	}

	.select-img {
		display: inline-block;
		width: 40px;
		height: 40px;
		margin: 0 -10px;
		background-image: url("../../assets/huanbao/option_nor.png");
		background-size: cover;
		vertical-align: -15px;
		cursor: pointer;
	}

	.select-img.select {
		background-image: url("../../assets/huanbao/option_press.png");
		background-size: cover;
	}

	.upload-btn {
		display: inline-block;
		width: 100px;
		height: 100px;
		text-align: center;
		line-height: 100px;
		margin: 10px 10px 0 0;
		border: 1px dashed;
		cursor: pointer;
	}

	.uk-notify {
		z-index: 10000;
	}

	.edit-btn {
		font-size: 12px;
		font-weight: normal;
		margin-left: 20px;
		color: #22bd33;
		cursor: pointer;
	}

	.el-checkbox__label {
		width: 600px;
		white-space: initial;
		display: inline-block;
		padding-left: 10px;
		line-height: 19px;
		font-size: 14px;
	}

	.standards-option {
		margin-bottom: 15px;
	}

	.standards-option .el-checkbox__input {
		cursor: pointer;
		outline: 0;
		line-height: 1;
		vertical-align: middle;
		margin-top: 3px;
	}

	.standards-option .el-radio {
		display: flex;
		white-space: normal !important;
		margin-bottom: 10px;
		white-space: normal !important;
		line-height: 20px;
	}

	.standards-option .el-radio+.el-radio {
		margin-left: 0;
	}

	.standards-option el-radio__label {
		display: block;
		font-size: 14px;
		padding-left: 10px;
	}

	.standards-option .el-checkbox+.el-checkbox {
		margin-left: 0;
		width: 500px;
	}

	.standards-option .el-checkbox {
		margin-bottom: 10px;
		line-height: 20px;
	}

	.el-checkbox__input.is-checked .el-checkbox__inner,
	.el-checkbox__input.is-indeterminate .el-checkbox__inner,
	.el-radio__input.is-checked .el-radio__inner {
		background-color: #22bd33;
		border-color: #22bd33;
	}

	.el-checkbox__input.is-checked+.el-checkbox__label,
	.el-radio__input.is-checked+.el-radio__label {
		color: #22bd33 !important;
	}

	.el-radio__input {
		white-space: nowrap;
		cursor: pointer;
		outline: 0;
		line-height: normal;
		vertical-align: middle;
		margin-top: 2px;
	}

	.el-radio__input.is-disabled.is-checked .el-radio__inner,
	.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner,
	.el-checkbox__input.is-disabled .el-checkbox__inner::after {
		background-color: #22bd33;
		border-color: #22bd33;
	}

	.el-radio__input.is-disabled.is-checked .el-radio__inner::after {
		background-color: #FFFFFF;
	}

	.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
		border-color: #FFFFFF;
	}

	.element-width {
		width: 180px !important;
		margin-left: 10px;
	}
</style>
